﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Library_DLL;
using Library_DLL.Entities;
using System.IO;
using System.Xml.Serialization; 

namespace RAD
{
    public partial class Form1 : Form
    {
        Radar Info = new Radar(); 

        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            lblRadarSystem1.Text = "Radar System 200";
            lblname.Text = "Name";
            lblspeed.Text = "Speed";
            lbldistance.Text = "Distance";
            lblaltitude.Text = "Altitude"; 
            radiobutton1.Text = "None";
            radioButton2.Text = "Bird";
            radioButton3.Text = "Enemy";
            radioButton4.Text = "Friendly"; 

        }

        private void btnrandom_Click(object sender, EventArgs e)
        {
            int speed, direction, altitude, distance;
            speed = RandomNumber(100, 1800);
            Info.Speed = speed;

            direction = RandomNumber(100, 2000);
            Info.Direction = direction;

            altitude = RandomNumber(500, 1000);
            Info.Altitude = altitude;

            distance = RandomNumber(700, 2000);
            Info.Distance = distance;

            textBox1.Text = Convert.ToString(speed);
            textBox2.Text = Convert.ToString(distance);
            textBox3.Text = Convert.ToString(altitude);
            textBox4.Text = Convert.ToString(direction); 





            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Radar));
                TextWriter textWriter = new StreamWriter("../../../Radar.xml");
                serializer.Serialize(textWriter, Info);
                textWriter.Close();
            }
            catch (Exception ex)
            {
            }


        }
        private int RandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max);
        }


        private void radiobutton1_CheckedChanged(object sender, EventArgs e)
        {
            btnrandom.Enabled = false;
            btnlockon.Enabled = false;
            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            textBox4.Enabled = false;
            txtboxname.Text = "None";
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            btnrandom.Enabled = true;
            btnlockon.Enabled = true;
            textBox1.Enabled = true;
            textBox2.Enabled = true;
            textBox3.Enabled = true;
            textBox4.Enabled = true;
            txtboxname.Text = "Bird";
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            btnrandom.Enabled = true;
            btnlockon.Enabled = true;
            textBox1.Enabled = true;
            textBox2.Enabled = true;
            textBox3.Enabled = true;
            textBox4.Enabled = true;
            txtboxname.Text = "Enemy";
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            btnrandom.Enabled = true;
            btnlockon.Enabled = true;
            textBox1.Enabled = true;
            textBox2.Enabled = true;
            textBox3.Enabled = true;
            textBox4.Enabled = true;
            txtboxname.Text = "Friendly";
        }
    }
}
